package view;

import java.util.Scanner;

import model.Directions;
import exceptions.NoSuchDirectionException;
import model.Player;

public class GameConsoleView {

	public static void printSuitableMessageAtTheEndOfGame(Player playerOne,
			Player playerTwo) {
		if (playerOne.getCurrentScore() > playerTwo.getCurrentScore()) {
			System.out.println(playerOne.getName()
					+ " is a winner with score of: "
					+ playerOne.getCurrentScore());
		} else if (playerOne.getCurrentScore() < playerTwo.getCurrentScore()) {
			System.out.println(playerTwo.getName()
					+ " is a winner with score of: "
					+ playerTwo.getCurrentScore());
		} else if (playerOne.getCurrentScore() == playerTwo.getCurrentScore()) {
			System.out.println("The game is a draw! Both players scored "
					+ playerOne.getCurrentScore() + " times.");
		}
	}

	/**
	 * Asking from the player to enter a direction.
	 * 
	 * @param Dinnamicaly
	 *            - Scanner.
	 * @return Enum - direction from a string.
	 * @throws NoSuchDirectionException
	 *             - when the direction is wrong.
	 */
	public static Directions enterDirection() {
		Scanner sc = new Scanner(System.in);

		for (;;) {
			try {

				System.out.println("Please enter a direction (L, R, U, D):");
				String directionText = sc.next();
				Directions selectedDirection = Directions
						.valueOf(directionText);
				return selectedDirection;

			} catch (IllegalArgumentException e) {
				System.out.println("The direction is incorrect!");
				System.out.println("Please try again.");
				continue;
			}
		}
	}
}
